<?php

namespace App\Listeners\Train;

use App\Events\Train\TicketQueryEvent;
use App\Trip\Train\Log\TicketQueryLog;
use App\Trip\Train\TrainQueryFromToData;
use Carbon\Carbon;
use Exception;

class TicketQueryLogListener
//    implements ShouldQueue
{
//    use InteractsWithQueue;

    private string $member_cache_key;

    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {

    }

    /**
     * Handle the event.
     *
     * @param object $event
     * @return void
     */
    public function handle(TicketQueryEvent $event)
    {
        $data = $event->data;
        $date = Carbon::today()->toDateString();
        try {
            /**
             * @var TrainQueryFromToData $from
             * @var TrainQueryFromToData $to
             */
            $from      = $data['from'];
            $to        = $data['to'];
            $ip        = $data['ip_address'];
            $query_log = new TicketQueryLog($from, $to, $date, $ip);
            $query_log->cacheAndPushQueue();
        } catch (Exception $exception) {
            return;
        }

    }
}
